var app = angular.module('JiangGanApp')
app.filter('translate',function(){
	    return function(word,group){
	    	if(word!=undefined&&group[word]!=undefined){
	        	return group[word];
	        }else{
	        	return word;
	        }
	    }
	});

app.filter('dfToColor',function(){
	return function(df,zdf){
		if(zdf==undefined){
			zdf=20
		}
		if(df/zdf>2/3){
			return '高危';
		}else if(df/zdf>1/3){
			return '重点';
		}else if(df/zdf>0){
			return '欠安';
		}else{
			return '安全'
		}
	}
})

app.filter('checkNull',function(){
	return function(val){
		if(val==undefined||val==""||val==null){
			return '无';
		}else{
			return val;
		}
	}

})

app.filter('Date2MonthWeek',function(){
	return function(day){
		var y = day.getYear();
		var m = day.getMonth()+1;
		var d = day.getDate();
		var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate(); 
		return Math.ceil( (d + 6 - w) / 7); 
	};
})


var types = {
	'10000': '案件',
	'20000': '交通',
	'30000': '火警',
	'40000': '求助',
	'50000': '咨询',
	'60000': '举报',
	'70000': '投诉监督',
	'80000': '事件',
	'90000': '灾害事故',
	'100000': '纠纷',
	'110000': '警务协助',
	'999000': '其它报警',
	'10': '刑事案件',
	'20': '治安案件',
	'130000': '扬言类',
	'120000': '医疗救助'
}
app.filter('c2type', function(){
	return function(code) {
		return types[code];
	}
})

//除重
app.filter('unique',function(){
    return function (collection, keyname) {
        var output = [],
            keys = [];

        angular.forEach(collection, function (item) {
            var key = item[keyname];
            if (keys.indexOf(key) === -1) {
                keys.push(key);
                output.push(item);
            }
        });

        return output;
    };
})

//筛选
app.filter('sort',function(){
    return function (collection, keyname ,keyvalue) {
        var output = [];
        if (keyname=='' || keyname==undefined || keyvalue=='' || keyvalue==undefined || keyvalue=='请选择'){
        	return collection;	//未定义时返回全部
        }else{
        	angular.forEach(collection, function (item) {
	            var key = item[keyname];
	            if (key == keyvalue) {
	                output.push(item);
	            }
       		});
        	return output;
        }
    };
})

